#include <sys/time.h>
#include <time.h>
#include <iostream>
#include <stdio.h>

class TimeClickCnt
{
private:
    /* data */
    struct timeval tv_;
    bool has_start_ = false;
public:
    TimeClickCnt(/* args */);
    ~TimeClickCnt();
    TimeClickCnt(const TimeClickCnt&) = delete;
    TimeClickCnt& operator=(const TimeClickCnt&) = delete;

    void startCnt();
    double stopCnt();
};

TimeClickCnt::TimeClickCnt(/* args */)
{
}

TimeClickCnt::~TimeClickCnt()
{
}

void TimeClickCnt::startCnt()
{
    gettimeofday(&tv_, NULL);
    has_start_ = true;

}

double TimeClickCnt::stopCnt()
{
    if(!has_start_){
        printf("Please start your cnt!!!\n");
        return 0.0;
    }
    struct timeval tv1;
    gettimeofday(&tv1, NULL);
    double dura;
    dura = (tv1.tv_sec - tv_.tv_sec) * 1000.0 + (tv1.tv_usec - tv_.tv_usec)/1000.0;
    printf("======================\n");
    printf("duration: %9.4lf\n", dura); 
    printf("======================\n"); 
    return dura;
}
